//
//  UITabBarController+Animation.m
//  ReviewDemo
//
//  Created by 龙 on 2018/5/10.
//  Copyright © 2018年 long. All rights reserved.
//

#import "UITabBarController+Animation.h"
#import "NSObject+Swizzling.h"
#import "UITabBarItem+Animation.h"

@implementation UITabBarController (Animation)

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        [self methodSwizzlingWithOriginalSelector:@selector(viewDidLoad) bySwizzledSelector:@selector(gyz_ViewDidLoad)];
    });
}


- (void)gyz_ViewDidLoad
{
    [self gyz_ViewDidLoad];
    self.delegate = self;
}


- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    if (tabBarController.selectedViewController != viewController)
    {
        [tabBarController.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop)
        {
            [obj.tabBarItem stopAnimation];
        }];
        
        [viewController.tabBarItem startAnimation];
    }
    
    return YES;
}

- (id)valueForUndefinedKey:(NSString *)key
{
    return nil;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    
}

@end
